package com.ben.multiple.mycat.two;

import org.junit.jupiter.api.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class PartitionByDateResource extends Base {
    private static final String LOCAL_URL_PREFIX = "/record";

    @Test
    void insert() {
        String url = GLOBAL_URL_PREFIX + LOCAL_URL_PREFIX + "/insert";
        Map<String, Object> body = new HashMap<>();
        body.put("id", 5);
        body.put("source", "192.168.0.5");
        body.put("amount", 1005);
        body.put("remark", "备注。。。");
        ResponseEntity<Object> entity = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(body), Object.class);
        this.print(entity);
    }

    @Test
    void insertBatch() {
        String url = GLOBAL_URL_PREFIX + LOCAL_URL_PREFIX + "/insert/batch";
        for (int i = 1; i <= 1000; i++) {
            List<Map<String, Object>> list = new ArrayList<>();
            for (int j = 1; j <= 10000; j++) {
                Map<String, Object> body = new HashMap<>();
                body.put("name", "测试公司" + i + j);
                body.put("licenseNo", "qwer" + i + j);
                body.put("corporation", "阿" + i + j);
                body.put("address", "湖北省武汉市青山区和平大道" + i + j + "号");
                body.put("remark", "备注。。。");
                body.put("status", true);
                list.add(body);
            }
            ResponseEntity<Object> entity = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(list), Object.class);
            System.out.println(entity.getBody() + " == " + LocalDateTime.now().toString());
        }
    }

    @Test
    void list() {
        String url = GLOBAL_URL_PREFIX + LOCAL_URL_PREFIX + "/list";
        ResponseEntity<Object> entity = restTemplate.exchange(url, HttpMethod.GET, null, Object.class);
        this.print(entity);
    }

}
